home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / expanded.lha / expanded / src / Scalar.C < prev    next >
C/C++ Source or Header  |  1992-03-19  |  4KB  |  165 lines

  1. //
  2. // Linear-Affine-Projective Geometry Package
  3. //
  4. // Scalar.C
  5. //
  6. // $Header$
  7. //
  8. // William J.R. Longabaugh 
  9. // University of Washington
  10. //
  11. // Implementation of the linear-affine-projective geometry
  12. // package described in William J.R. Longabaugh, "An Expanded
  13. // System for Coordinate-Free Geometric Programming", Master's 
  14. // thesis, University of Washington, 1992.
  15. //
  16. // Copyright (c) 1992, William J.R. Longabaugh
  17. //   Copying, use and development for non-commercial purposes permitted.
  18. //   All rights for commercial use reserved.
  19. //   This software is unsupported and without warranty; it is
  20. //   provided "as is".
  21. //
  22. // ***********************************************************************
  23.  
  24. #include "Lap.h"
  25.  
  26. // ***********************************************************************
  27. // ***********************************************************************
  28. //
  29. // AugScalar Class
  30. //
  31. // ***********************************************************************
  32. // ***********************************************************************
  33. //
  34. // Public member functions
  35. //
  36. // ***********************************************************************
  37. //
  38. // Default augmented scalar equals 0.0:
  39. //
  40.  
  41. AugScalar::AugScalar(void) : m(1, 2)
  42. {
  43.   is_inf = FALSE;
  44.   m[0][0] = 0.0;
  45.   m[0][1] = 1.0;
  46.  
  47. // ***********************************************************************
  48. //
  49. // Create an augmented scalar with a finite value:
  50. //
  51.  
  52. AugScalar::AugScalar(Scalar v) : m(1, 2)
  53. {
  54.   is_inf = FALSE;
  55.   m[0][0] = v;
  56.   m[0][1] = 1.0;
  57.  
  58. // ***********************************************************************
  59. //
  60. // Create an augmented scalar with the value INFINITY:
  61. //
  62.  
  63. AugScalar::AugScalar(Infnum n) : m(1, 2)
  64. {
  65.   if (n == INFINITY) {
  66.     is_inf = TRUE;
  67.   } else {
  68.     errh.ErrorExit("AugScalar::AugScalar(Infnum)",
  69.            "Illegal value for building augmented scalar",
  70.                    ErrVal("Value of argument = ", n));
  71.   }
  72.   m[0][0] = 1.0;
  73.   m[0][1] = 0.0;
  74. }
  75.  
  76. // ***********************************************************************
  77. //
  78. // Automatically cast an augmented scalar into a scalar:
  79. //
  80.  
  81. AugScalar::operator Scalar()
  82. {
  83.   if (!is_inf) {
  84.     return (m[0][0] / m[0][1]);
  85.   } else {
  86.     errh.ErrorExit("AugScalar::operator Scalar()",
  87.            "Attempted to cast INFINITY to a scalar");
  88.   }
  89. }
  90.  
  91. // ***********************************************************************
  92. //
  93. // Get the value of the augmented scalar (This is just an explicit form of
  94. // casting to a scalar).
  95. //
  96.  
  97. Scalar AugScalar::Value(void)
  98. {
  99.   if (!is_inf) {
  100.     return (m[0][0] / m[0][1]);
  101.   } else {
  102.     errh.ErrorExit("Scalar AugScalar::Value(void)",
  103.            "INFINITE augmented scalar cannot return a value");
  104.   }
  105. }
  106.  
  107. // ***********************************************************************
  108. //
  109. // Need to do memberwise initialization, since Matrix class members need
  110. // to do memberwise initialization:
  111. //
  112.  
  113. AugScalar::AugScalar(AugScalar& a) : m(a.m)
  114. {
  115.   is_inf = a.is_inf;
  116. }
  117.  
  118. // ***********************************************************************
  119. //
  120. // Need to do memberwise assignment, since Matrix class members need
  121. // to do memberwise assignment:
  122. //
  123.  
  124. AugScalar& AugScalar::operator=(AugScalar& a)
  125. {
  126.   is_inf = a.is_inf;
  127.   m = a.m;
  128.   return (*this);
  129. }
  130.  
  131. // ***********************************************************************
  132.  
  133. void AugScalar::debug_out(ostream& c, int indent)
  134. {
  135.   char *ibloc = new char[indent + 1];
  136.   for (int i = 0; i < indent; i++) {
  137.     *(ibloc + i) = ' ';
  138.   }
  139.   *(ibloc + indent) = '\0';
  140.  
  141.   c << ibloc << ast;
  142.   c << ibloc << "Augmented scalar object\n";
  143.   if (is_inf) {
  144.     c << ibloc << "Value = INFINITY\n";
  145.   } else {
  146.     c << ibloc << "Value = " << (m[0][0] / m[0][1]) << "\n";
  147.   }
  148.   c << ibloc << ast;
  149.  
  150.   delete ibloc;
  151.   return;
  152. }
  153.  
  154. // ***********************************************************************
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.